{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import threading\n",
    "import time\n",
    "from queue import Queue"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def job(l,q):\n",
    "    for i in range(len(l)):\n",
    "        l[i]=l[i]**2\n",
    "    q.put(l)\n",
    "        \n",
    "def multithreading():\n",
    "    q = Queue()\n",
    "    threads = []\n",
    "    data = [[1,2,3],[3,4,5],[2,2,5]]\n",
    "    for i in range(3):\n",
    "        t = threading.Thread(target=job,args=(data[i],q))\n",
    "        t.start()\n",
    "        threads.append(t)\n",
    "    for thread in threads:\n",
    "        thread.join()\n",
    "    results = []\n",
    "    for i in range(3):\n",
    "        results.append(q.get())\n",
    "    print(results)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1, 4, 9], [9, 16, 25], [4, 4, 25]]\n"
     ]
    }
   ],
   "source": [
    "if __name__=='__main__':\n",
    "    multithreading()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
